<?php
namespace app\index\controller;

use app\common\service\Menu as MenuService;
use app\common\service\Post as PostService;
use think\Request;


class Index
{
    protected $param = [];

    public function __construct(){
        $menuService = new MenuService();
        $menuTree = $menuService -> getMenusTree();
        $this->param['menuTree'] = $menuTree;
    }

    /**
     * 首页
     * @return \think\response\View
     */
    public function index(){
        $postService = new PostService();
        $posts = $postService ->paginate();

        $this->param['posts'] = $posts;

        return view('',$this->param);
    }

    /**
     * 列表页
     */
    public function posts(){
        return view();
    }

    /**
     * 内容页
     */
    public function post(Request $request){
        $id = $request -> param("id");
        $postService = new PostService();
        $post = $postService->find($id);

        $this->param['post'] = $post;

        return view('',$this->param);
    }


    public function permission(){
        $permission = ["admin/menu/delete","admin/menu/update","admin/menu/create","admin/menu/edit","admin/menu/add","admin/menu/index",'admin/user/delete',"admin/user/update","admin/user/edit","admin/user/index","admin/user/create","admin/user/add","admin/upload/upload","admin/role/update","admin/role/delete","admin/role/create","admin/role/edit","admin/role/add","admin/role/index","admin/permission/update","admin/permission/index","admin/index/index","admin/permission/add","admin/permission/edit","admin/permission/create","admin/index/main","admin/permission/delete"];
        $permission = serialize($permission);
        return $permission;
    }
}
